<?php
	require $_SERVER['DOCUMENT_ROOT'] . '/deviantpic/inc/database.php';
	require $_SERVER['DOCUMENT_ROOT'] . '/deviantpic/inc/doctype.php';

	$search = "";
	if (isset($_GET['picture'])) $search = $_GET['picture'];

	//Search
	$pictures	= array();
	$result		= mysql_query("SELECT * FROM photos WHERE title LIKE '%$search%'") or die(mysql_error());

	//if there's a result
	if (mysql_num_rows($result) > 0) {
		$row = mysql_fetch_array($result);
		while ($row) {
			$pictures[] = $row;
			$row = mysql_fetch_array($result);
		}
	}
?>

    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <title>deviantPIC - Search picture</title>
    </head>
    <body>
		<!-- Header -->
		<?php require $_SERVER['DOCUMENT_ROOT'] . '/deviantpic/inc/header.php'; ?>

		<!-- Content -->
		<div id="body">
			<h2>
				Result for <span class="searched">
				<?php
					echo $search;
				?></span>
			</h2>

			<!-- Pictures -->
			<div class="pictures" id="searched-pictures">
				<ul class="pictures">
					<?php
						foreach ($pictures as $picture) {
					?>
					<li class="picture">
						<a href=<?php echo "/deviantpic/picture/view.php?id=" . $picture['id']; ?>>
							<img src=<?php echo "'" . $picture['photo'] . "' alt= '" . $picture['title'] . "'"; ?> width="160" height="160"/>
						</a>
					</li>

					<?php
						}
					?>
				</ul>
			</div>
		</div>

		<!-- Footer -->
		<?php require $_SERVER['DOCUMENT_ROOT'] . '/deviantpic/inc/footer.php'; ?>
    </body>
</html>